<template>
  <section class="recommend_banner">
    <div class="title">
      <h4>{{ item.name }}</h4>
      <div v-if="item.more">
        更多
        <i class="iconfont icon-youjiantou"></i>
      </div>
    </div>
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div class="swiper-slide" v-for="v1 in item.detail" :key="v1.img_banner_id">
          <div class="item" v-for="(v2, v2ind) in v1.banner" :key="v2ind">
            <img :src="v2.good_img" alt="" />
            <p class="bookName" v-show="v2.good_name">{{ v2.good_name }}</p>
            <p>{{ v2.good_price }}</p>
          </div>
        </div>
      </div>
      <div class="swiper-button-next"></div>
      <div class="swiper-button-prev"></div>
    </div>
  </section>
</template>

<script>
import Swiper from "swiper";
export default {
  props: ["item"],
  methods: {},
  mounted() {
    var swiper = new Swiper(".swiper-container", {
      slidesPerView: 3,
      direction: getDirection(),
      navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
      },
      on: {
        resize: function () {
          swiper.changeDirection(getDirection());
        },
      },
    });
    function getDirection() {
      var windowWidth = window.innerWidth;
      var direction = windowWidth <= 750 ? "horizontal" : "vertical";
      return direction;
    }
  },
};
</script>

<style lang="less" scoped>
.swiper-container {
  width: 100%;
  height: 100%;
}

.swiper-slide {
  width: 33.3%;
  font-size: 18px;
  background: #fff;
  /* Center slide text vertically */
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  flex-wrap: wrap;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;

  .item {
    // height: 201px;
    padding-bottom: 5px;
    img {
      width: 100%;
    }
    p {
      padding-top: 5px;
      font-size: 13px;
      &:nth-child(2) {
        height: 32px;
        border-top: 1px solid rgba(136, 136, 136, 0.3);
        margin: 5px 5px 0px 0px;
        font-size: 13px;
        color: #464646;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      &:nth-child(3) {
        margin-top: 10px;
        font-size: 15px;
        color: #ff463c;
      }
    }
  }
}

@media (max-width: 750px) {
  .swiper-button-next {
    right: 20px;
    transform: rotate(90deg);
  }

  .swiper-button-prev {
    left: 20px;
    transform: rotate(90deg);
  }
}
.recommend_banner {
  width: 100%;
  padding: 0px 10px;
  box-sizing: border-box;
  background-color: white;
  margin: 10px 0px;
  border-top: 1px solid rgba(136, 136, 136, 0.3);
  border-bottom: 1px solid rgba(136, 136, 136, 0.3);
  .title {
    display: flex;
    justify-content: space-between;
    padding: 10px 0px;
    h4 {
      font-size: 14px;
    }
    div {
      font-size: 12px;
      color: #969696;
      padding-bottom: 10px;
      i {
        font-size: 12px;
      }
    }
  }
}
</style>